package com.chance.cc.crawler.development.bootstrap.tianmao;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import com.chance.cc.crawler.development.utils.RedisReader;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerDataType.comment;
import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;

/**
 * @author bx
 * @date 2020/11/11 0011 10:44
 */
public class TianmaoCommentStart {

    public static final String domainId = "tianmao";
    public static final String userAgentUrl = "https://fake-useragent.herokuapp.com/browsers/0.1.11";
    public static void main(String[] args) {

//        dev();
        prod();
    }

    private static void dev(){
        CrawlerRequestRecord requestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domainId, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl("https://rate.tmall.com/list_detail_rate.htm?itemId=43928349416" +
                        "&sellerId=890482188&order=1&currentPage=1&append=0&content=1&callback=jsonp_tbcrate_reviews_list")
                .httpHead("referer","https://detail.tmall.com/item.htm?spm=a220m.1000858.1000725.1.6a902be8m5HPI4&id=43928349416")
                .releaseTime(System.currentTimeMillis())
                .needWashed(true)
                .resultLabelTag(comment)
                .filter(CrawlerEnum.CrawlerRecordFilter.keyOrDateRange)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(domainId))
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*50,null))
                .build();

        DevCrawlerController.builder()
                .triggerInfo(domainId,domainId,System.currentTimeMillis(),domainId)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domainId))
                .consoleResultPipeline()
                .fileResultPipeline("D:\\chance\\log\\tianmao_comment.log",false)
                .requestRecord(requestRecord)
                .build().start();
    }

    private static void prod(){
        RedisReader redisReader = new RedisReader("192.168.1.215",6379,4);
        CrawlerRequestRecord crawlerRequestRecord = redisReader.recordPop("crawler-tianmao-comment-daily-supplement-queue_list", "crawler-tianmao-comment-daily-supplement-queue_map");




        DevCrawlerController.builder()
                .triggerInfo(domainId,domainId,System.currentTimeMillis(),domainId)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue("aaa"))
                .consoleResultPipeline()
                .requestRecord(crawlerRequestRecord)
                .build("com.chance.cc.crawler.development.scripts.tianmao").start();
    }
}
